﻿using System;
using System.ComponentModel;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace LIK.WakeOnLan.Forms
{
    public partial class FormShutDown : XtraForm
    {
        public string HostName
        {
            set { txtPCName.Text = value; }
        }

        public FormShutDown()
        {
            InitializeComponent();
        }

        private void btnRestart_Click(object sender, EventArgs e)
        {
            if (this.Valid())
            {
                string errorMessage;
                //if (!RemoteShutDown.Shutdown(txtPCName.Text, txtUserName.Text, txtPassword.Text, true, out errorMessage))
                //{
                //    XtraMessageBox.Show(errorMessage, "Error");
                //}
            }
        }

        private void btnShutDown_Click(object sender, EventArgs e)
        {
            if (this.Valid())
            {
                string errorMessage;
                //if (!RemoteShutDown.Shutdown(txtPCName.Text, txtUserName.Text, txtPassword.Text, false, out errorMessage))
                //{
                //    XtraMessageBox.Show(errorMessage, "Error");
                //}
            }
        }

        private bool Valid()
        {
            this.dxErrorProvider.ClearErrors();
            this.ValidateChildren(ValidationConstraints.Enabled);
            return !dxErrorProvider.HasErrors;
        }

        private void txtPCName_Validating(object sender, CancelEventArgs e)
        {
            if (string.IsNullOrEmpty(txtPCName.Text))
            {
                this.dxErrorProvider.SetError(this.txtPCName, "Enter Valid Remote PC Name");
            }
        }

    }
}
